﻿/*
+----------------------------------------------------------------------+
| CORE                                                                 |
+----------------------------------------------------------------------+
| Copyright © 2013 - 2018, The Machine Studio.                         |
+----------------------------------------------------------------------+
| See https://gitee.com/signorinotang/ServerStudy for last version     |
|                                                                      |
+----------------------------------------------------------------------+
| Author: Donney <Email: donney_luck@sina.cn>                          |
|                <QQ: 116297528>                                       |                                                                     |
+----------------------------------------------------------------------+
*/

#include "Config.h"

namespace core {
#if CORE_PLATFORM == CORE_PLATFORM_MAC
	bool file_exists(const char* filename) {
		struct stat sb;
		return stat(filename, &sb) == 0;
	}
	
	uint64_t file_time(const char* filename) {
		struct stat sb;
		if (stat(filename, &sb) != 0)
			return 0;
		else
			return (uint64_t)sb.st_mtime;
	}

	void make_path(const char * dir)
	{
		char tmp[1024];
		char * p = NULL;
		int len;
		snprintf(tmp, sizeof(tmp), "%s", dir);
		len = (int)strlen(tmp);
		if (tmp[len - 1] == '/')
			tmp[len - 1] = 0;
		for (p = tmp + 1; *p; p++)
		{
			if (*p == '/')
			{
				*p = 0;
				mkdir(tmp, S_IRWXU);
				*p = '/';
			}
		}
		mkdir(tmp, S_IRWXU);
	}

	void split_path_file(char ** p, char ** f, const char * pf)
	{
		const char * slash = pf, *next;
		while ((next = strpbrk(slash + 1, "\\/"))) slash = next;
		if (pf != slash) slash++;
		*p = strndup(pf, slash - pf);
		*f = _strdup(slash);
	}
#elseif CORE_PLATFORM == CORE_PLATFORM_WINDOWS
#elseif CORE_PLATFORM == CORE_PLATFORM_UNIX
#endif
}